<!DOCTYPE html>
<html >
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>调群</title>
    <link href="../css/mui.min.css" rel="stylesheet" type="text/css">
    <link href="../css/home.page.css" rel="stylesheet" />
    <link href="../bootstrap-select/bootstrap-select.css" rel="stylesheet">
    <link href="../css/bootstrap.min.css" rel="stylesheet" >
	<link href="../css/mui.picker.min.css" rel="stylesheet" >
    <script charset="UTF-8" src="../js/jquery.min.js"></script>
    <script charset="UTF-8" src="../js/config.js"></script>
    <script charset="UTF-8" src="../js/core.js"></script>
    <script charset="UTF-8" src="../js/cipher-core.js"></script>
    <script charset="UTF-8" src="../js/tripledes.js"></script>
    <script charset="UTF-8" src="../js/mode-ecb.js"></script>
    <script charset="UTF-8" src="../js/zepto.min.js"></script>
    <script charset="UTF-8" src="../js/spin.min.js"></script>
    <script charset="UTF-8" src="../js/mui.min.js"></script>
    <script charset="UTF-8" src="../js/testActivityName.js"></script>
    <script charset="UTF-8" src="../js/simple.tool.js"></script>
	<script charset="UTF-8" src="../js/mui.picker.min.js"></script>
    <style>
        label{
            text-align: right;
        }
        .btn-default{
            border-color: snow;
        }
        .form-control{
            -webkit-box-shadow: inset 0 0px 0px rgba(0,0,0,.075);
        }
        .form-group{
            border-bottom: 1px solid #f6f6f6;max-width: 720px;height: 55px;
        }
    </style>
</head>
<body class="white-bg" >
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" style="width: 95%;" id="form-tonegroup-add" target="ifr">
        <input name="parity" class="form-control" type="text"  id="parity" style="display: none">
        <div class="form-group" style="margin-bottom: 0px;border-bottom: 0px solid #f6f6f6;">
            <div class="head-jnx" onclick="record()">
                <img src="../img/fanhui@3x.png" />
                <p>调群</p>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>耳号：</label>
            <div class="col-xs-7">
                <select class="selectpicker form-control m-b" data-live-search="true" name="cowId"  id="overbit" data-size="10" title="选择耳号" onchange="getHouse()" required>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>转组日期：</label>
            <div class="col-xs-7">
                <div class="input-group date">
                    <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                    <input id="transferDate" type="text" onfocus=this.blur() onclick="dtPicker('transferDate')">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>栋舍：</label>
            <div class="col-xs-7">
                <input name="houseId" class="form-control" type="text"  style="display: none" id="houseId">
                <input name="cow_house_name" class="form-control" type="text" readonly="readonly" id="cow_house_name">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>分群：</label>
            <div class="col-xs-7">
                <input name="swarm" class="form-control" type="text"  style="display: none" id="swarmId">
                <input name="swarm_name" class="form-control" type="text" readonly="readonly" id="swarm">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>新栋舍：</label>
            <div class="col-xs-7">
                <select name="newHouseId" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="newHouseId" onchange="getNewSwarm()"  required>

                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>新分群：</label>
            <div class="col-xs-7">
                <select name="newSwarm" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="newSwarm" onclick="inspectNumber()" required>
					<option value=''>请选择</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>调群原因：</label>
            <div class="col-xs-7">
                <select name="transferReason" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="transferReason" required>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label"><span style="color: red;font-size: initial;">*</span>调群执行人：</label>
            <div class="col-xs-7">
                <select name="transferExecutor" style="/* display: table-cell; */vertical-align: middle;text-align: left;width: 100%;" id="transferExecutor" required>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-4 control-label">备注：</label>
            <div class="col-xs-7">
                <input name="remark" class="form-control" type="text" placeholder="请输入">
            </div>
        </div>
        <div class="form-group">
            <div style="width: 320px; margin: auto;">
                <div class="quxiao-btn" style="margin-right: 15px;" onclick="record()">取消</div>
                <input type="submit" value="保存信息" class="quxiao-btn" style="background: #0078fb; color: #FFFFFF;border-radius: 55px;" >
                <div class="clear"></div>
            </div>
        </div>
    </form>
</div>
<iframe name='ifr' id="ifr" style='display: none;'></iframe><!--表单提交防止刷新-->
<script src="../js/bootstrap.min.js"></script>
<script src="../bootstrap-select/bootstrap-select.js"></script>
<script type="text/javascript">
	var mapS={}
	mapS.url="getsynestrusdata";
	var overbitList=ajaxRequestPostS(mapS);
    window.onload=breedLoad();
	var i = setTimeout(function(){
		overbitList = JSON.parse(localStorage.getItem('getsynestrusdata'));
		console.log(overbitList)
	    if(overbitList != 0){
			loadSelect('overbit',overbitList,'cow_id','overbit');//耳号
			$('.selectpicker').selectpicker('refresh');
		}
	},900);
    function breedLoad() {//获得下拉数据
		var resultData = JSON.parse(localStorage.getItem('addtonegroupdata'));
        breedHtml(resultData.data);
		$("#transferDate").val(getDateNow());
    }
    $("#form-tonegroup-add").submit(function () {
        map={};
        map=$('#form-tonegroup-add').serializeObject();
        map.url="addtonegroup";
        map.overbit=$("#overbit option:selected").text();
        var resultData=ajaxRequestPostSubmit(map);
        if (resultData.head.info == "增加成功") {
            setTimeout(function () {
                record();
            }, 1000);
        }
    });
    function record() {//返回记录
        window.location = "../记录.html";
    }
    function breedHtml(resultData) {//加载下拉
		var userName = resultData.realName;
        var cowHouseList=resultData.cowHouseList;
        loadSelect('newHouseId',cowHouseList,'cowHouseId','cowHouseName');//新牛舍
        var reasonList=resultData.reasonList;
        loadSelect('transferReason',reasonList,'code','name');//调群原因
        var userList=resultData.userList;
        loadSelect('transferExecutor',userList,'user_id','real_name',userName);//调群执行人
        $('.selectpicker').selectpicker('refresh');
    }
    function loadSelect(id,data,code,name,userName) {
        $("#"+id).html("");
        $("#"+id).append("<option value=''>请选择</option>");
        for (i=0;i<data.length;i++){//
            var str='';
			if(userName != null && data[i][name] == userName){
				str='<option value="'+data[i][code]+'" selected>'+data[i][name]+'</option>';
			}else{
				str='<option value="'+data[i][code]+'">'+data[i][name]+'</option>';
			}
            $("#"+id).append(str);
        }
    }
    function getHouse() {
        var map={}
        map.url="gethouse";
        map.cow_id=$("#overbit").val();
        var resultData=ajaxRequestPost(map);
        var cow=resultData.data.cowList[0];
        $("#houseId").val(cow.cow_house_id);
        $("#cow_house_name").val(cow.cow_house_name);
        $("#parity").val(cow.parity);
        $("#swarmId").val(cow.swarmId);
        $("#swarm").val(cow.swarm);
    }
    function getNewSwarm() {//获得分群
        var map={}
        map.url="getClustering";
        map.parent_id=$("#newHouseId").val();
        var resultData=ajaxRequestPost(map);
        var swarmList=resultData.data.swarmList;
        loadSelect('newSwarm',swarmList,'cowHouseId','cowHouseName');
        $('.selectpicker').selectpicker('refresh');
    }
	function inspectNumber(){
		var reasonSort = $("#newHouseId").val();
		var diseaseDetails = $("#newSwarm").val();
		if((diseaseDetails == null || diseaseDetails == "") && (reasonSort == null || reasonSort == "")){
			mui.toast("请先选择[新栋舍]");
		}
	}
</script>
</body>
</html>